//
//  HighScoresScreen.m
//  iSudoku
//
//  Created by acumen on 5/25/13.
//  Copyright 2013 Tri Vo. All rights reserved.
//

#import "HighScoresScreen.h"


@implementation HighScoresScreen

+ (id)scene {
    CCScene *scene = [CCScene node];
    HighScoresScreen *highScore = [HighScoresScreen node];
    [scene addChild:highScore];
    return scene;
}

- (id)init {
    self = [super init];
    if (self) {
        // Do something here
        [self initScreen];
    }
    return self;
}

- (void)dealloc {
    [mListHighScores release];
    [mTableView release];
    [super dealloc];
}

#pragma mark - Screen methods

- (void) initScreen {
    CGSize winSize = [[CCDirector sharedDirector] winSize];
    
    
    mTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, winSize.height/2 - 300, 320, 300) style:UITableViewStylePlain];
    [mTableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [mTableView setSeparatorColor:[UIColor clearColor]];
    [mTableView setDelegate:self];
    [mTableView setDataSource:self];
    [mTableView setBackgroundColor:[UIColor clearColor]];
    
    [[CCDirector sharedDirector].view addSubview:mTableView];
    [[CCDirector sharedDirector].view sendSubviewToBack:mTableView];
    mListHighScores = [[NSMutableArray alloc] initWithObjects:@"HELLO", @"WORLD", @"IM", @"ACUMEN", nil];
    CCMenuItemFont *back = [CCMenuItemFont itemWithString:@"Back" block:^(id sender) {
        [mTableView removeFromSuperview];
        [[CCDirector sharedDirector] popSceneWithTransition:[CCTransitionSlideInL class] withTime:0.5f];
    }];
    
    CCMenu *menu = [CCMenu menuWithItems:back, nil];
    [menu alignItemsVertically];
    [menu setPosition:ccp(winSize.width/2, winSize.height/2 - 100)];
    [self addChild:menu];
    
    [mTableView reloadData];
}

#pragma mark - UITableView Delegate Methods

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellIdentifier = @"CellId";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease];
    }
    NSString *content = [mListHighScores objectAtIndex:indexPath.row];
    UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 52)];
    [lbl setCenter:CGPointMake(lbl.center.x, cell.center.y)];
    [lbl setText:content];
    [lbl setTextColor:[UIColor whiteColor]];
    [lbl setBackgroundColor:[UIColor clearColor]];
    [lbl setTextAlignment:UITextAlignmentCenter];
    [cell addSubview:lbl];
    [lbl release];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 52;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return mListHighScores.count;
}

@end
